package jmujava8;

import java.util.ArrayList;
import java.util.Scanner;
public class Main {
    private static Scanner in;
    public static void main(String[] args)
    {
        in=new Scanner(System.in);
        ArrayList<String> strList=new ArrayList<>();
        while (true)
        {
            String s=in.next();
            while(!s.equals("!!end!!"))
            {
                strList.add(s);
                s=in.next();
            }
            if(strList.size()>0)
            {
                strList.add(0,"begin");
                strList.add(strList.size(),"end");
            }
            System.out.println(strList);
            String str=in.next();
            int a;
            a=strList.indexOf(str);
            if(a>=0)
            {
                System.out.println("true");
                System.out.println(a);
                System.out.println(strList.lastIndexOf(str));
            }
            else {
                System.out.println("false");
                System.out.println(a);
            }
            System.out.println(strList.get(0));
            strList.remove(0);
            System.out.println(strList);
            str=in.next();
            strList.set(1,str);
            System.out.println(strList);
            str=in.next();
            ArrayList<String> strList1=new ArrayList<>();
            for (String e:strList)
            {
                    if(e.indexOf(str)>=0)
                        strList1.add(e);
            }
            System.out.println(strList1);
            a=strList.indexOf(str);
            if(a>=0)
                strList.remove(a);
            System.out.println(strList);
            strList.clear();
            System.out.println(strList+" "+strList.size()+","+strList.isEmpty());
        }
    }
}
